<template>
	<view class="container">
		<template v-for="(item, index) in pgList">
			<uni-card :title="item.pgbt" :extra="item.pgsj">
				<view class="uni-body">
					<uni-row class="demo-uni-row">
						<uni-col :span="12">
							<text class="text">是否升白：{{item.sfsb == 1 ? '是':'否'}}</text>
						</uni-col>
						<uni-col :span="12">
							<text class="text">是否更换方案：{{item.ghfa == 1 ? '是':'否'}}</text>
						</uni-col>
					</uni-row>
					<uni-row class="demo-uni-row">
						<uni-col>
							<text class="text">备注：{{item.remark}}</text>
						</uni-col>
					</uni-row>
					<uni-row class="demo-uni-row">
						<uni-col :span="12">
							<view class="tag-view">
								<uni-tag v-show="!isDisabled" text="删除" @click="del(item.id)" type="error" />
							</view>
						</uni-col>
						<uni-col :span="12">
							<view class="tag-view" @click="addFzhl(item.id)" style="text-align: right;">
								<uni-tag text="编辑" type="primary" />
							</view>
						</uni-col>
					</uni-row>
				</view>
			</uni-card>
		</template>
		<uni-fab ref="fab" v-show="!isDisabled" horizontal="right" @fabClick="fabClick" />
	</view>
</template>

<script>
	import storage from '@/utils/storage'
import { delXfzhl,getDicts,sfkybjData } from "@/api/trms/trms"
import { getPg } from "@/api/trms/query"
export default {
	data() {
		return {
			patientId: null,
			isDisabled: false,
			userId: null,
			pgList: []
		}
	},
	onLoad: function(option) {
		this.patientId = option.patientId;
		this.userId = option.userId;
		console.log("进入随访信息列表页面、参数：",this.patientId)
		sfkybjData(this);
		if(this.patientId){
			// 查询列表
			this.getDataByPatientId();
		}
	},
	onReady() {
		
	},
	methods: {
		/**
		 * 新增
		 */
		fabClick(){
			this.addFzhl(null);
		},
		/**
		 * 获取数据
		 */
		getDataByPatientId(){
			getPg(this.patientId,1).then(response => {
			  this.pgList = response.data;
			});
		},
		/**
		 * 删除
		 * @param {Object} id
		 */
		del(id){
			if(this.isDisabled){
				// 禁用时，不能删除
				this.$modal.msgError('只能删除自己创建的信息');
				return;
			}
			let that = this;
			uni.showModal({
				title: '提示',
				content: '确认删除该条新辅助化疗信息吗？',
				cancelText: '取消',
				confirmText: '删除',
				confirmColor: 'red',
				cancelColor: '#000000',
				success: function(res){
					if(res.confirm){
						// 确认
						that.delId(id);
					}else{
						// 取消
					}
				}
			});
		},
		delId(id){
			if(this.isDisabled){
				this.$modal.msgError('只能删除自己创建的信息');
				return;
			}
			delXfzhl(id).then(response => {
			  if(response.code == 200){
				  this.$modal.msgSuccess("删除成功");
				  this.getDataByPatientId();
				  return;
			  }
			  this.$modal.msgSuccess(response.msg);
			});
		},
		/**
		 * 新增辅助化疗
		 * @param {Object} id
		 */
		addFzhl(id){
			if(!id){
				id = '';
			}
			let that = this;
			let size = 1;
			if(this.pgList.length > 0){
				size = this.pgList.length + 1;
			}
			uni.navigateTo({
				url: '/pages/trms/dtpg/xfzhledit?id='+id+'&patientId='+that.patientId+'&size='+size+'&userId='+that.userId,
				events: {
				    // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
				    listFzhl: function(data) {
					  if(data && data.data == 'refPage'){
						  // 重新查询
						  that.getDataByPatientId();
					  }
				    }
				},
				success: function(res) {
					// 通过eventChannel向被打开页面传送数据
					res.eventChannel.emit('listFzhl', { id: id, patientId: that.patientId,size:size,userId:that.userId })
				}
			});
		}
	}
}
</script>

<style>
	.uni-body .demo-uni-row {
		margin-top: 5px;
	}
</style>